package com.ewhale.feitengguest.presenter.user.mine;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.dto.ThirdInfoDto;
import com.ewhale.feitengguest.view.user.mine.WithdrawView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;

import java.util.HashMap;
import java.util.Map;

public class WithdrawPrensenter extends IPresenter {
    public void whitDraw(int withType, int money) {
        mView.showProLoading();
        Map<String, Object> params = new HashMap<>();
        params.put("amount", money);
        params.put("type", withType);
//        if (withType == 1) {
//            params.put("wechatImg", weChatImg);
//        } else {
//            params.put("aliAccount", aliAccount);
//        }
        request(1, ApiHelper.USER_API.withdrawal(params), null);
    }

    public void getThirdInfo() {
        mView.showProLoading();
        request(2, ApiHelper.USER_API.getWithdrawalDetail(), null);
    }

    public void bindThird(String openid, int type) {
        mView.showProLoading();
        Map<String,Object> params = new HashMap<>();
        params.put("openid",openid);
        params.put("type",type);
        request(3, ApiHelper.USER_API.bindThree(openid,type), params);
    }

    public void bindWeChatName(String name) {
        mView.showProLoading();
        request(4, ApiHelper.USER_API.bindWechatName(name), null);
    }

    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode) {
            case 1:
                ((WithdrawView) mView).withSuccess();
                break;
            case 2:
                ((WithdrawView) mView).showThirdInfo((ThirdInfoDto)result);
                break;
            case 3:
                ((WithdrawView) mView).bindSuccess((Map<String,Object>) data);
                break;
            case 4:
                ((WithdrawView) mView).bindWeChatName();
                break;
        }
    }
    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode, e.getCode(), e.getDisplayMessage());
    }
}
